package doantotnghiep.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="ChiTietNhapHang")
public class ImportedDetail {
	
	private int id;
	private Medicament medicament;
	private int numberOfBatch;
	private float importCost;

	private ImportedMedicament importedMedicament;
	
	@Id
	@GeneratedValue
	@Column(name="MaCTNH")
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "MaPhieuNhap")
	public ImportedMedicament getImportedMedicament() {
		return importedMedicament;
	}
	
	public void setImportedMedicament(ImportedMedicament importedMedicament) {
		this.importedMedicament = importedMedicament;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "MaSanPham")
	public Medicament getMedicament() {
		return medicament;
	}
	
	public void setMedicament(Medicament medicament) {
		this.medicament = medicament;
	}
	
	@Column(name="SoLuong")
	public int getNumberOfBatch() {
		return numberOfBatch;
	}
	
	public void setNumberOfBatch(int numberOfBatch) {
		this.numberOfBatch = numberOfBatch;
	}	
	
	private Set<MedicamentBatch> detailBatchs = new HashSet<MedicamentBatch>();
	
	@OneToMany(mappedBy = "importDetail", fetch = FetchType.LAZY) 
	@Fetch(FetchMode.JOIN)
	public Set<MedicamentBatch> getDetailBatchs() {
		return detailBatchs;
	}

	public void setDetailBatchs(Set<MedicamentBatch> detailBatchs) {
		this.detailBatchs = detailBatchs;
	}

	@Column(name="ThanhTien")
	public float getImportCost() {
		return importCost;
	}

	public void setImportCost(float importCost) {
		this.importCost = importCost;
	}
   }
